const baseurl='https://devapi.qweather.com/v7/weather/now?key=02413365df61406abcf374b5c7e72b53&location='
Page({
  data:{
    city:"",
    temperature:'',
    direct:'',
    latitude:'0',
    longitude:'0',
  },
  input(e){
    console.log(e)
    this.setData({
      city:e.detail.value
    })
  },
  search(){
    let city = this.data.city
    let latitude = this.data.latitude
    let longitude = this.data.longitude
    let url = `${baseurl}${longitude},${latitude}`
    console.log(url)
    let that = this
    wx.request({
      url,
      success(e){
        console.log(e)
        let {temp,windDir} = e.data.now
        that.setData({
          temperature:temp,
          direct:windDir
        })
      }
    })
  },
  onLoad(){
    let that = this
    wx.getLocation({
      success(e){
        let {latitude,longitude} = e
        that.setData({
          latitude,longitude
        })
      }
    })
  }
})